var t = getApp();

Page({
    data: {
        active: 0,
        date: "",
        fieldsType: "month",
        dateBol: !0,
        datestr: "",
        date_2: "",
        fieldsType_2: "month",
        dateBol_2: !0,
        datestr_2: "",
        time_types: 1,
        year: "",
        month: "",
        year_2: "",
        month_2: "",
        time_types_2: 1,
        datas: "",
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        sales_type: "commonly",
        month_sales: "",
        year_sales: ""
    },
    onLoad: function(t) {
        this.setData({
            year: String(new Date().getFullYear()),
            month: this.data.month ? this.data.month : String(new Date().getMonth() + 1 > 9 ? new Date().getMonth() + 1 : "0" + String(new Date().getMonth() + 1)),
            year_2: String(new Date().getFullYear()),
            month_2: this.data.month ? this.data.month : String(new Date().getMonth() + 1 > 9 ? new Date().getMonth() + 1 : "0" + String(new Date().getMonth() + 1))
        }), this.getData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        "subordinate" == this.data.sales_type && (this.data.isLoadMore ? this._getMoreData(this.data.page) : console.log("没有更多数据"));
    },
    onShareAppMessage: function() {},
    _getMoreData: function() {
        var a = this;
        if (this.data.isLoadMore = !1, !(a.data.page >= a.data.total_page)) {
            a.data.page += 1;
            var e = {};
            e.year_2 = this.data.year_2, e.page = this.data.page, 1 == this.data.time_types_2 ? (e.time_types_2 = 1, 
            e.month_2 = this.data.month_2) : 2 == this.data.time_types_2 && (e.time_types_2 = 2);
            var s = t.getNetAddresss("plugin.goods-sales.frontend.controllers.list.index");
            t._postNetWork({
                url: s,
                showToastIn: !1,
                data: e,
                success: function(t) {
                    var e = t.data;
                    if (1 != e.result) return a.data.page = a.page - 1, void (a.data.isLoadMore = !1);
                    var s = e.data.subordinate.data;
                    a.setData({
                        datas: a.data.datas.concat(s)
                    });
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    bindDateChange: function(t) {
        console.log("picker发送选择改变，携带值为", t.detail.value);
        var a = t.detail.value, e = "";
        a && ((e = a.split("-"))[1] ? (this.setData({
            year_2: e[0],
            month_2: e[1]
        }), e = e[0] + "年" + e[1] + "月") : (this.setData({
            year_2: e[0]
        }), e = e[0] + "年"), this.getnext(), this.setData({
            datestr: e
        }));
    },
    dateBtn: function(t) {
        var a = t.currentTarget.dataset.datetype;
        this.setData({
            fieldsType: a
        }), "year" == a ? this.setData({
            dateBol: !1,
            time_types_2: 2
        }) : this.setData({
            dateBol: !0,
            time_types_2: 1
        }), this.getnext();
    },
    bindDateChange_2: function(t) {
        console.log("picker发送选择改变，携带值为", t.detail.value);
        var a = t.detail.value, e = "";
        a && ((e = a.split("-"))[1] ? (this.setData({
            year: e[0],
            month: e[1]
        }), e = e[0] + "年" + e[1] + "月") : (this.setData({
            year: e[0]
        }), e = e[0] + "年"), this.setData({
            datestr_2: e
        }), this.getData());
    },
    dateBtn_2: function(t) {
        var a = t.currentTarget.dataset.datetype;
        this.setData({
            fieldsType_2: a
        }), "year" == a ? this.setData({
            dateBol_2: !1,
            time_types: 2
        }) : this.setData({
            dateBol_2: !0,
            time_types: 1
        }), this.getData();
    },
    getData: function() {
        var a = this, e = {};
        1 == this.data.time_types ? (e.time_types = 1, e.year = this.data.year, e.month = this.data.month) : 2 == this.data.time_types && (e.time_types = 2, 
        e.year = this.data.year);
        var s = t.getNetAddresss("plugin.goods-sales.frontend.controllers.list.index");
        t._postNetWork({
            url: s,
            showToastIn: !1,
            data: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    month_sales: e.data.month_sales,
                    year_sales: e.data.year_sales
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    onChange: function(t) {
        1 == t.detail.index ? (this.data.sales_type = "subordinate", this.getnext()) : (this.data.sales_type = "commonly", 
        this.getData());
    },
    getnext: function() {
        var a = this, e = {};
        this.data.isLoadMore = !0, this.data.total_page = 0, e.year_2 = this.data.year_2, 
        e.page = this.data.page, 1 == this.data.time_types_2 ? (e.time_types_2 = 1, e.month_2 = this.data.month_2) : 2 == this.data.time_types_2 && (e.time_types_2 = 2);
        var s = t.getNetAddresss("plugin.goods-sales.frontend.controllers.list.index");
        t._postNetWork({
            url: s,
            showToastIn: !1,
            data: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.data.total_page = e.data.subordinate.last_page, a.data.total_page || (a.data.total_page = 0), 
                a.setData({
                    datas: e.data.subordinate.data
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    }
});